/***************************************/
/********* Jose Delgado Perez **********/
/********* josedelgado@ula.ve **********/
/*********    LaSDAI - ULA    **********/
/*********     29-09-2011     **********/
/***************************************/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include "bibliotecas/percepcion/comunicacionPic.h"
#include <sys/shm.h>

#define FALSE 0
#define TRUE 1


int main(){
	unsigned char *buf= NULL;
	int Id_Memoria, fd, leer;
	int i;
	key_t Clave;
	Clave = ftok ("/bin/ls", 53);
	if (Clave == -1){
		perror("No consigo clave para memoria compartida \n");
		exit(0);
	}
	Id_Memoria = shmget (Clave, sizeof(unsigned char)*10, 0777 | IPC_CREAT);
	if (Id_Memoria == -1){	
		perror("No consigo Id para memoria compartida \n");
		exit (0);
	}
	buf = (unsigned char *)shmat(Id_Memoria, (char *)0, 0);
	if (buf == NULL){
		perror("No consigo memoria compartida \n");
		exit (0);
	}
	buf[8] = 0;
	leer = readData(fd, 2, &buf[8]);
	if(leer == -1) exit(1);
	buf[7] = 0;
	while(1){
		fd = openPort();
		leer = readData(fd, 7, buf);
		if(leer == -1) exit(1);
		buf[7] = buf[7]+1;
		for(i=0; i<=7; i++){
			printf("Sensor: %d valor %x  \n", i, buf[i]);
		}
	}
	return 0;
}


